VERSION := 0.5
VERTITLE := lines-$(VERSION)
ARCHIVE := lines_$(VERSION).tar.gz

CFLAGS:=-Wall -O2 $(shell sdl-config --cflags) 
#-DMAEMO

LDFLAGS:=$(shell sdl-config --libs) -lSDL_image -lSDL_mixer

SRC     := board.c graphics.c main.c sound.c
OBJ     := $(patsubst %.c, %.o, $(SRC))

all: color-lines
PREFIX:=/usr/local

BINDIR:=$(DESTDIR)/$(PREFIX)/games/
GAMEDATADIR:=$(DESTDIR)/$(PREFIX)/share/games/color-lines/

svnclean:
	svn st | grep "^?" | awk '{ print $$2 }' | while read l; do $(RM) -rf $$l; done

tarball: clean svnclean
	ln -sf ./ $(VERTITLE)
	tar -cz --exclude $(VERTITLE)/$(VERTITLE) --exclude svg --exclude .svn --exclude $(ARCHIVE) -f $(ARCHIVE) $(VERTITLE)/*
	$(RM) -f $(VERTITLE)

$(OBJ): %.o : %.c
	$(CC) -c $(<) $(I) $(CFLAGS) -DGAMEDATADIR=\"$(GAMEDATADIR)\"

color-lines:  $(OBJ)
	cat color-lines.desktop.in | sed -e "s|@BINDIR|$(BINDIR)|g" > color-lines.desktop
	$(CC) $(CFLAGS) $(LDFLAGS) $(^) -o $(@) 
	strip color-lines

clean:
	rm -f *.o color-lines

install: all
	install -d $(BINDIR)
	install -m 0755 color-lines $(BINDIR)
	install -d $(GAMEDATADIR)/gfx
	install -d $(GAMEDATADIR)/icon
	install -m 0644 icon/color-lines.png $(GAMEDATADIR)/icon
	install -d $(GAMEDATADIR)/sounds
	install -m 0644 sounds/* $(GAMEDATADIR)/sounds/
	install -m 0644 gfx/atomic.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/ball.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/bg.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/boom.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/cell.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/color1.png $(GAMEDATADIR)/gfx		
	install -m 0644 gfx/color2.png $(GAMEDATADIR)/gfx		
	install -m 0644 gfx/color3.png $(GAMEDATADIR)/gfx		
	install -m 0644 gfx/color4.png $(GAMEDATADIR)/gfx	
	install -m 0644 gfx/color5.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/color6.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/color7.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/fnt.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/info_off.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/info_on.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/info.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/joker.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/music_off.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/music_on.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/paint.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/pb_logo.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/vol_empty.png $(GAMEDATADIR)/gfx
	install -m 0644 gfx/vol_full.png $(GAMEDATADIR)/gfx
	install -d $(DESTDIR)/$(PREFIX)/share/pixmaps
	install -d $(DESTDIR)/$(PREFIX)/share/applications/
	install -m 0644 icon/color-lines.png $(DESTDIR)/$(PREFIX)/share/pixmaps
	install -m 0644 color-lines.desktop $(DESTDIR)/$(PREFIX)/share/applications/color-lines.desktop
